-- | Build a tree from a seed value

data Tree a   = N {
    name :: a,   -- ^ label value
    args :: Forest a -- ^ zero or more child trees
  } deriving (Show,Eq)

type Forest a = [Tree a]

instance Functor Tree where
  fmap f (N x ts) = N (f x) (map (fmap f) ts)
    
-- unfoldTree :: (b -> (a, [b])) -> b -> Tree a
unfoldTree f b = let (a, bs) = f b in N a (unfoldForest f bs)

-- unfoldForest :: (b -> (a, [b])) -> [b] -> Forest a
unfoldForest f = map (unfoldTree f)

showTree t = fmap show t

mytree n z = unfoldTree  (\x->(x,[x+1..n])) z

main = print (mytree 3 0)

